import {reqChangeRoom, reqCloseRoom, reqGetAllStateZeroOrderList, reqOpenRoom} from "@/api";

const state = {
    stateZeroOrderList:[],
}
const actions = {
    // 创建订单（开房）
    async openRoom({commit}, config){
        let result = await reqOpenRoom(config);
        if (result.code==200){
            this._vm.$message({
                showClose:true,
                message:'开房成功！',
                type:"success"
            })
        }else{
            this._vm.$message({
                showClose:true,
                message:'开房失败！',
                type:"error"
            })
        }
    },
    // 获取state为0的订单列表
    async getStateZeroOrderList({commit}){
        let result = await reqGetAllStateZeroOrderList();
        if (result.code==200){
            commit('GETSTATEZEROORDERLIST', result.data);
        }
    },
    // 退房
    async reqCloseRoom({commit}, config){
        let result = await reqCloseRoom(config);
        if (result.code==200){
            this._vm.$message({
                showClose:true,
                message:'退房成功！',
                type:'success'
            })
        }else{
            this._vm.$message({
                showClose:true,
                message:'退房失败！',
                type:'error'
            })
        }
    },
    // 换房
    async changeRoom({commit}, config){
        let result = await reqChangeRoom(config);
        if (result.code==200){
            this._vm.$message({
                showClose:true,
                message:'换房成功！',
                type:'success'
            })
        }else{
            this._vm.$message({
                showClose:true,
                message:'换房失败！',
                type:'error'
            })
        }
    }
}
const mutations = {
    GETSTATEZEROORDERLIST(state, data){
        state.stateZeroOrderList = data;
    }
}
const getters = {
    getCanCloseOrderList(){
        return state.stateZeroOrderList || [];
    }
}

export default {
    state,
    actions,
    mutations,
    getters
}